home *** CD-ROM | disk | FTP | other *** search
/ Greenhouse Effect Detection Expriment / NASA Greenhouse Effect Detection Expriment 1992 - Disc 2.iso / software / dos / cdf22pc / src / include / cdflib.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-12  |  36.5 KB  |  1,079 lines

  1. /******************************************************************************
  2. *
  3. *  NSSDC/CDF                    Header file for CDF library.
  4. *
  5. *  Version 3.0, 24-Feb-92, ST Systems (STX)
  6. *
  7. *  Modification history:
  8. *
  9. *   V1.0  22-Jan-91, R Kulkarni/J Love    Original version (for CDF V2.0).
  10. *
  11. *   V2.0   3-Jun-91, J Love        Renamed (was cdf_internal.h).
  12. *                    Modified for CDF V2.1, namely the
  13. *                    moving of constant macros to "cdf.h"
  14. *                    for the INTERNAL interface and the
  15. *                    single/multi file option.  Renamed
  16. *                    some symbols for clarity.
  17. *   V2.1  24-Jun-91, J Love        Fixed for SGi port.
  18. *   V2.2   8-Aug-91, J Love        Added 'Eof' (feof).  Added some
  19. *                    miscellaneous macro definitions.
  20. *                    Renamed (was cdflib.h).  Added support
  21. *                    for Cray/UNICOS.  Added 'Exit' and
  22. *                    'ExitBAD'.  Added VIO_FOR_STREAM.
  23. *                    Functions in VIO were renamed to avoid
  24. *                    collisions on SGi/IRIX.
  25. *   V3.0  24-Feb-92, J Love        IBM PC & HP-UX port.  CDF V2.2.
  26. *
  27. ******************************************************************************/
  28.  
  29. #if !defined(___cdflib_h___)
  30. #define ___cdflib_h___
  31.  
  32. /*****************************************************************************
  33. * Include files.
  34. *****************************************************************************/
  35.  
  36. #include "cdfdist.h"
  37.  
  38. /*****************************************************************************
  39. * Typedefs for fields.
  40. *****************************************************************************/
  41.  
  42. typedef long Int32;
  43.  
  44. /*****************************************************************************
  45. * Magic numbers.
  46. *****************************************************************************/
  47.  
  48. #define V1_MAGIC_NUMBER_flip    0x0F000000   /* What a V1 magic number looks
  49.                         like when the bytes are
  50.                         flipped.  The bytes will be
  51.                         flipped on a VAX because the
  52.                         longword was assumed to be in
  53.                         network order and then flipped
  54.                         to VAX order.  The bytes will
  55.                         be flipped on a Sun, Cray,
  56.                         MIPSEB, and MIPSEL because the
  57.                         longword was assumed to already
  58.                         be in network order (the same
  59.                         as those machines) but the byte
  60.                         order in memory is reversed
  61.                         from that of a VAX (where all
  62.                         V1 CDFs were created). */
  63.  
  64. #define V2_MAGIC_NUMBER        0x0000FFFF
  65.  
  66. /*****************************************************************************
  67. * Optimization/configuration.
  68. *****************************************************************************/
  69.  
  70. #define GUESS_V1_VECTOR_SIZES    0    /* When TRUE (1), the number of records
  71.                        in CDF V1 vector (variable) files
  72.                        will be guessed at. */
  73.  
  74. #define FULL_ERROR_CHECKING    1     /* When TRUE (1), all error checking
  75.                        code will be compiled into the
  76.                        library. */
  77.  
  78. #define INCLUDE_STATUS_TEXT    1    /* When TRUE (1), explanation text for
  79.                        status codes is compiled into the
  80.                        library. */
  81.  
  82. /*****************************************************************************
  83. * Reserved values.
  84. *****************************************************************************/
  85.  
  86. #define RESERVED_CDFID        (CDFid) (-1)    /* indicates that a CDFid
  87.                            hasn't been selected yet */
  88.  
  89. #define RESERVED_CDFSTATUS  (CDFstatus) (-1)    /* indicates that a CDFstatus
  90.                            hasn't been selected yet */
  91.  
  92. #define RESERVED_ENTRYNUM   (long) (-1)        /* indicates that an entry
  93.                            number hasn't been selected
  94.                            yet */
  95.  
  96. /*****************************************************************************
  97. * CDF V1.1 parameters.
  98. *****************************************************************************/
  99.  
  100. #define V1_DATATYPE_STRING_LEN    8
  101. #define V1_CDR_OFFSET        4    /* aka, Header record */
  102. #define V1_GDR_OFFSET        1576
  103. #define V1_FIRST_VDR_OFFSET    1728
  104. #define V1_MAX_DIMS        10
  105. #define V1_VAR_NAME_LEN        8
  106. #define V1_ATTR_NAME_LEN    8
  107.  
  108. #define    CDFV1_DATA_TYPE_LEN    8
  109. #define    CDFV1_ATTR_NAME_LEN    8
  110. #define    CDFV1_VAR_NAME_LEN    8
  111. #define CDFV1_CDF_NAME_LEN    100
  112.  
  113. #define    CDFV1_OK          0
  114. #define    CDFV1_DEFAULT_RCODE      1
  115. #define    CDFV1_NO_SUCH_VAR      45
  116. #define    CDFV1_NO_SUCH_ATTR      30
  117. #define    CDFV1_NO_SUCH_ATTR_ENTRY  25
  118.  
  119. #define    TWO_BLANKS        8224    /* "lowest" 2-character attribute or
  120.                        variable name possible (although
  121.                        nobody in their right mind would
  122.                        use it) */
  123.  
  124. /*****************************************************************************
  125. * CDF V2.0+ parameters.
  126. *****************************************************************************/
  127.  
  128. #define V2_MAGIC_OFFSET            0
  129. #define V2_CDR_OFFSET            8
  130.  
  131. #define N_VXR_ENTRIES            10
  132.  
  133. #if defined(__IBMPC__)
  134. #define nCACHE_BUFFERs_CDF        10
  135. #else
  136. #define nCACHE_BUFFERs_CDF        750
  137. #endif
  138.  
  139. #define nCACHE_BUFFERs_CDH        2
  140. #define nCACHE_BUFFERs_Vnn        10
  141.  
  142. #define MIN_nEXTEND_BYTES_single    512
  143. #define MIN_nEXTEND_RECS_single        1
  144.  
  145. #define MIN_nEXTEND_RECS_multi    1      /* don't set this greater than 1
  146.                          unless the algorithm to extend
  147.                          variable files is changed - extra
  148.                          writes to the files may result */
  149.  
  150. /*****************************************************************************
  151. * Operating system dependent definitions.
  152. *****************************************************************************/
  153.  
  154. #if defined(vms)
  155. #define VIO_FOR_STREAM        1
  156. #endif
  157.  
  158. #if defined(unix) | defined(__MSDOS__)
  159. #define VIO_FOR_STREAM        1
  160. #endif
  161.  
  162. #if VIO_FOR_STREAM
  163. #include "vio.h"
  164. #define File VFILE
  165. #define Open(filespec,a_mode,n_buffers) Vopen(filespec,a_mode,n_buffers)
  166. #define Seek(fp,offset,direction) Vseek(fp,offset,direction)
  167. #define Read(buffer,itemsize,numitems,fp) Vread(buffer,itemsize,numitems,fp)
  168. #define Write(buffer,itemsize,numitems,fp) Vwrite(buffer,itemsize,numitems,fp)
  169. #define Tell(fp) Vtell(fp)
  170. #define Eof(fp) Veof(fp)
  171. #define Close(fp) Vclose(fp)
  172. #else
  173. #define File FILE
  174. #define Open(filespec,a_mode) fopen(filespec,a_mode)
  175. #define Seek(fp,offset,direction) fseek(fp,offset,direction)
  176. #define Read(buffer,itemsize,numitems,fp) fread(buffer,itemsize,numitems,fp)
  177. #define Write(buffer,itemsize,numitems,fp) fwrite(buffer,itemsize,numitems,fp)
  178. #define Tell(fp) ftell(fp)
  179. #define Eof(fp) feof(fp)
  180. #define Close(fp) fclose(fp)
  181. #endif
  182.  
  183. /*****************************************************************************
  184. * Machine dependent definitions.
  185. *****************************************************************************/
  186.  
  187. #if defined(sun) | defined(MIPSEB) | defined(IBMRS) | defined(HP)
  188. #define DecodeBuffer(encoding,dataType,numElements,buffer) {}    /* null */
  189. #endif
  190.  
  191. #if defined(vax) | defined(MIPSEL) | defined(__IBMPC__)
  192. #define DecodeBuffer(encoding,dataType,numElements,buffer) \
  193. if (encoding == NETWORK_ENCODING) xdr_decode (dataType, numElements, buffer)
  194. #endif
  195.  
  196. /*****************************************************************************/
  197.  
  198. #if defined(sun) | defined(MIPSEB) | defined(IBMRS) | defined(HP)
  199. #define getint32(fp,x) Read(&x,4,1,fp)
  200. #define putint32(fp,x) Write(&x,4,1,fp)
  201. #endif
  202.  
  203. #if defined(vax) | defined(MIPSEL) | defined(__IBMPC__)
  204. #define getint32(fp,x) { \
  205. long tmp; \
  206. Read(&tmp,4,1,fp); \
  207. x = ntohl(tmp); \
  208. }
  209. #define putint32(fp,x) { \
  210. long tmp; \
  211. tmp = htonl(x); \
  212. Write(&tmp,4,1,fp); \
  213. }
  214. #endif
  215.  
  216. /*****************************************************************************/
  217.  
  218. #if defined(vax)
  219. #define getint32H(fp,x) Read(&x,4,1,fp)
  220. #define putint32H(fp,x) Write(&x,4,1,fp)
  221. #endif
  222.  
  223. /*****************************************************************************
  224. * Miscellaneous macros.
  225. *****************************************************************************/
  226.  
  227. #define getbytes(len,x,fp) Read(x,1,len,fp)
  228. #define putbytes(len,x,fp) Write(x,1,len,fp)
  229.  
  230. /*****************************************************************************
  231. * Internal CDF/variable status codes.
  232. *****************************************************************************/
  233.  
  234. #define CDF_CLOSED    (long) 501
  235. #define CDF_READ_ONLY    (long) 502
  236. #define CDF_READ_WRITE    (long) 503
  237. #define VAR_CLOSED    (long) 504
  238. #define VAR_OPENED    (long) 505
  239. #define NO_VAR_FILE    (long) 506
  240.  
  241. /*****************************************************************************
  242. * Variable flag bit positions (bit 0 is Least Significant Bit).  For flag
  243. * bits in the VDR.
  244. *****************************************************************************/
  245.  
  246. #define VAR_RECVARY_BIT        0    /* record variance:
  247.                          set = VARY,
  248.                          clear = NOVARY */
  249. #define VAR_FILLVALUE_BIT    1    /* fill value:
  250.                          set = specified,
  251.                          clear = not specified (use
  252.                              default) */
  253.  
  254. /*****************************************************************************
  255. * CDF flag bit positions (bit 0 is Least Significant Bit).  For flag bits in
  256. * the CDR.
  257. *****************************************************************************/
  258.  
  259. #define CDF_MAJORITY_BIT    0    /* majority: set = row major,
  260.                              clear = column major */
  261. #define CDF_FORMAT_BIT        1    /* format: set = single file,
  262.                            clear = multi file */
  263.  
  264. /*****************************************************************************
  265. * Record types.
  266. *****************************************************************************/
  267.  
  268. #define UNUSED_      (Int32) (-1)    /* no longer used (original record moved) */
  269.  
  270. #define CDR_      (Int32) 1    /* CDF Descriptor Record */
  271. #define GDR_      (Int32) 2    /* Global Descriptor Record */
  272. #define VDR_      (Int32) 3    /* Variable Descriptor Record */
  273. #define ADR_      (Int32) 4    /* Attribute Descriptor Record */
  274. #define AEDR_      (Int32) 5    /* Attribute Entry Descriptor Record */
  275. #define VXR_      (Int32) 6    /* Variable indeX Record */
  276. #define VVR_      (Int32) 7    /* Variable Values Record */
  277.  
  278. /*****************************************************************************
  279. * Base record sizes (bytes).
  280. *****************************************************************************/
  281.  
  282. #define CDR_BASE_SIZE        48
  283. #define GDR_BASE_SIZE        60
  284. #define VDR_BASE_SIZE        64
  285. #define VXR_BASE_SIZE        20
  286. #define VVR_BASE_SIZE        8
  287. #define ADR_BASE_SIZE        52
  288. #define AEDR_BASE_SIZE        48
  289.  
  290. /*****************************************************************************
  291. * CDR structure.
  292. *****************************************************************************/
  293.  
  294. struct CDRstruct {
  295. Int32    RecordSize;    /* Size of record (bytes) */
  296. Int32    RecordType;    /* Type of record (ie. CDR) */
  297. Int32    GDRoffset;    /* File offset to GDR (bytes) */
  298. Int32    Version;    /* CDF Version Number */
  299. Int32    Release;    /* CDF Release Number */
  300. Int32    Encoding;    /* Encoding of CDF File    */
  301. Int32    Flags;        /* Flags: bit 0 -> majority
  302.                         if set, ROW major
  303.                         if clear, COLUMN major
  304.                   bit 1 -> format
  305.                         if set, SINGLE file
  306.                         if clear, MULTI file */
  307. Int32    rfuA;        /* reserved for future use (value = 0) */
  308. Int32    rfuB;        /* reserved for future use (value = 0) */
  309. Int32    Increment;    /* CDF Increment Number (Vversion.release.increment),
  310.                always 0 for V2.0 CDFs */
  311. Int32    rfuD;        /* reserved for future use (value = -1) */
  312. Int32    rfuE;        /* reserved for future use (value = -1) */
  313. char    copyright[CDF_COPYRIGHT_LEN];
  314.             /* copyright message for CDF */
  315. };
  316.  
  317. /*****************************************************************************
  318. * GDR structure.
  319. *
  320. * Note(s):
  321. *   The Eof field was not maintained for V2.0 CDFs (it will contain a random
  322. * value).  When a V2.0 CDF is opened, the end-of-file will be determined and
  323. * placed in this field (in memory, not on disk yet).  If the V2.0 CDF is
  324. * modified (access changed to READ/WRITE), the release will be changed to 1
  325. * and this field will contain the correct value (when written to disk).  The
  326. * V2.0 CDF will have been automatically converted to a V2.1 CDF.
  327. *
  328. *****************************************************************************/
  329.  
  330. struct GDRstruct {
  331. Int32    RecordSize;    /* Size of current record (bytes) */
  332. Int32    RecordType;    /* Type of record (ie. GDR) */
  333. Int32    VDRhead;    /* File offset to first VDR (bytes) */
  334. Int32    garbage1;    /* value is undefined (random) */
  335. Int32    ADRhead;    /* File offset to first ADR (bytes) */
  336. Int32    eof;        /* If V2.0 CDF, value is undefined (random).
  337.                If V2.1 CDF, end-of-file (byte offset). */
  338. Int32    NumVar;        /* Number of Variables */
  339. Int32    NumAttr;    /* Number of Attributes    */
  340. Int32    MaxRec;         /* Maximum record number in CDF    */
  341. Int32    NumDims;    /* Number of CDF dimensions */
  342. Int32    rfuA;        /* reserved for future use (value = 0) */
  343. Int32    rfuB;        /* reserved for future use (value = 0) */
  344. Int32    rfuC;        /* reserved for future use (value = 0) */
  345. Int32    rfuD;        /* reserved for future use (value = -1) */
  346. Int32    rfuE;        /* reserved for future use (value = -1) */
  347. Int32    *DimSizes;    /* Size of each dimension */
  348. };
  349.  
  350. /*****************************************************************************
  351. * VDR structure.
  352. *****************************************************************************/
  353.  
  354. struct VDRstruct {
  355. Int32    RecordSize;    /* Size of current record (bytes) */
  356. Int32    RecordType;    /* Type of record (ie. VDR) */
  357. Int32    VDRnext;    /* File offset to next VDR (bytes) */
  358. Int32    DataType;    /* DataType of Variable */
  359. Int32    MaxRec;        /* Maximum record number for variable */
  360. Int32    VXRhead;    /* File offset to first VXR (bytes).  Value will be
  361.                0 if MULTI_FILE format */
  362. Int32    VXRtail;    /* File offset to last VXR (bytes).  Value will be 0
  363.                if MULTI_FILE format */
  364. Int32    Flags;        /* Flags: bit 0 -> record variance
  365.                         if set, VARY
  366.                         if clear, NOVARY */
  367. Int32    rfuA;        /* reserved for future use (value = 0) */
  368. Int32    rfuB;        /* reserved for future use (value = 0) */
  369. Int32    rfuC;        /* reserved for future use (value = -1) */
  370. Int32    REFvarNum;    /* Number of referenced variable (If -1, use
  371.                variable's number in this CDF.  If -1, then
  372.                REFfilename should be null.) */
  373. char    REFfilename[CDF_VAR_FILE_NAME_LEN+1];
  374.             /* Name of referenced variable file (If null, use
  375.                this CDF's file name.  If null, then REFvarNum
  376.                should be -1.) */
  377. Int32    NumElem;    /* Number of elements of DataType (should be 1 if not
  378.                CDF_CHAR or CDF_UCHAR) */
  379. Int32    Num;        /* Variable number */
  380. Int32    rfuD;        /* reserved for future use (value = -1) */
  381. Int32    NextendRecs;    /* number of records to extend variable when new
  382.                allocations are necessary (if 0, use default) */
  383. char    Name[CDF_VAR_NAME_LEN+1];
  384.             /* Variable name */
  385. Int32    *DimVarys;    /* dimension variances */
  386. void    *FillValue;    /* fill value for extending variable (present only if
  387.                VAR_FILLVALUE_BIT set in "Flags") */
  388. };
  389.  
  390. /*****************************************************************************
  391. * VXR structure.
  392. *****************************************************************************/
  393.  
  394. struct VXRstruct {
  395. Int32    RecordSize;    /* Size of current record (bytes) */
  396. Int32    RecordType;    /* Type of record (ie. VXR) */
  397. Int32    VXRnext;    /* File offset to next VXR (bytes) */
  398. Int32    Nentries;    /* Number of index entries (entries not being used
  399.                contain -1 in each field) */
  400. Int32    NusedEntries;    /* Number of index entries actually used */
  401. Int32    *FirstRec;    /* First record number in VVR */
  402. Int32    *LastRec;    /* Last record number in VVR */
  403. Int32    *VVRoffset;    /* File offset to VVR (bytes) */
  404. };
  405.  
  406. /*****************************************************************************
  407. * VVR structure.
  408. *****************************************************************************/
  409.  
  410. struct VVRstruct {
  411. Int32    RecordSize;    /* Size of current record (bytes) */
  412. Int32    RecordType;    /* Type of record (ie. VVR) */
  413. void    *buffer;    /* Record(s) */
  414. };
  415.  
  416. /*****************************************************************************
  417. * ADR structure.
  418. *****************************************************************************/
  419.  
  420. struct ADRstruct {
  421. Int32    RecordSize;    /* Size of current record (bytes) */
  422. Int32    RecordType;    /* Type of record (ie. ADR) */
  423. Int32    ADRnext;    /* File offset to next ADR (bytes) */
  424. Int32    AEDRhead;    /* File offset to first AEDR (bytes) */
  425. Int32    Scope;        /* variable or global */
  426. Int32    Num;        /* Attribute Id Number */
  427. Int32    NumEntries;    /* Number of attribute entries */
  428. Int32    MaxEntry;    /* Maximum attribute entry number */
  429. Int32    rfuA;        /* reserved for future use (value = 0) */
  430. Int32    rfuB;        /* reserved for future use (value = 0) */
  431. Int32    rfuC;        /* reserved for future use (value = 0) */
  432. Int32    rfuD;        /* reserved for future use (value = -1) */
  433. Int32    rfuE;        /* reserved for future use (value = -1) */
  434. char    Name[CDF_ATTR_NAME_LEN+1];
  435.             /* Attribute name */
  436. };
  437.  
  438. /*****************************************************************************
  439. * AEDR structure.
  440. *****************************************************************************/
  441.  
  442. struct AEDRstruct {
  443. Int32    RecordSize;    /* Size of current record (bytes) */
  444. Int32    RecordType;    /* Type of record (ie. AEDR) */
  445. Int32    AEDRnext;    /* File offset to next AEDR */
  446. Int32    AttrNum;    /* Attribute Id Number        */
  447. Int32    DataType;    /* Attribute Data Type        */
  448. Int32    Num;        /* Entry number (variable number or arbitrary global
  449.                entry number) */
  450. Int32    NumElem;    /* Number of elements of DataType */
  451. Int32    rfuA;        /* reserved for future use (value = 0) */
  452. Int32    rfuB;        /* reserved for future use (value = 0) */
  453. Int32    rfuC;        /* reserved for future use (value = 0) */
  454. Int32    rfuD;        /* reserved for future use (value = -1) */
  455. Int32    rfuE;        /* reserved for future use (value = -1) */
  456. void    *Value;        /* Attribute Value */
  457. };
  458.  
  459. /*****************************************************************************
  460. * Structure for variable index related data.
  461. *****************************************************************************/
  462.  
  463. struct vixSTRUCT {
  464. struct    vixSTRUCT *vixNext;        /* pointer to next 'vix' */
  465. long    VXRoffset;            /* offset in file of VXR */
  466. struct    VXRstruct VXR;            /* VXR */
  467. };
  468.  
  469. /*****************************************************************************
  470. * Structure for variable related data.
  471. *****************************************************************************/
  472.  
  473. struct varSTRUCT {
  474. struct    varSTRUCT *varNext;
  475. File    *fp;            /* For a MULTI file CDF, this is set when
  476.                    the variable file is first opened.
  477.                    For a SINGLE file CDF, this is set to the
  478.                    'fp' of the CDF (the .CDF file contains
  479.                    the variable data) */
  480. long    status;
  481. long    NvalueBytes;        /* number of bytes per value */
  482. long    NphyRecValues;        /* number of physical values per record */
  483. long    NvirtRecValues;        /* number of virtual values per record */
  484. long    NphyRecBytes;        /* number of physical bytes per record */
  485. long    NvirtRecBytes;        /* number of virtual bytes per record */
  486. long    defaultNextendRecs;    /* default number of records to extend when
  487.                    new allocations are necessary (only used
  488.                    if VDR doesn't contain number to use) */
  489. long    *products;
  490. long    *hypProducts;
  491. long    *hypIndices;
  492. long    *hypTops;
  493. long    accessed_at;
  494. long    seqValueOffset;        /* Used for SEQUENTIAL ACCESS.  The "current"
  495.                    value (not byte) offset. */
  496. long    VDRoffset;
  497. struct    VDRstruct VDR;
  498. struct    vixSTRUCT *vixHead;
  499. struct    vixSTRUCT *vixTail;
  500. };
  501.  
  502. /*****************************************************************************
  503. * Structure for attribute entry related data.
  504. *****************************************************************************/
  505.  
  506. struct entrySTRUCT {
  507. struct    entrySTRUCT *entryNext;
  508. long    AEDRoffset;
  509. struct    AEDRstruct AEDR;
  510. };
  511.  
  512. /*****************************************************************************
  513. * Structure for attribute related data.
  514. *****************************************************************************/
  515.  
  516. struct attrSTRUCT {
  517. struct    attrSTRUCT *attrNext;
  518. long    ADRoffset;
  519. struct    ADRstruct ADR;
  520. struct    entrySTRUCT *entryHead;
  521. struct    entrySTRUCT *entryTail;
  522. long    V1dataType;            /* used for V1.1 CDFs only (all
  523.                        entries had same data type) */
  524. long    V1numBytes;            /* used for V1.1 CDFs only */
  525. };
  526.  
  527. /*****************************************************************************
  528. * Structure for CDF related data.
  529. *****************************************************************************/
  530.  
  531. struct cdfSTRUCT {
  532. CDFid    id;
  533. Int32    magic_number;
  534. char    filename[CDF_FILE_NAME_LEN+1];
  535. File    *fp;
  536. long    status;
  537.  
  538. long    recnum;
  539. long    reccount;
  540. long    recinterval;
  541. long    *indices;
  542. long    *counts;
  543. long    *intervals;
  544.  
  545. long    CDRoffset;
  546. struct    CDRstruct CDR;
  547.  
  548. long    GDRoffset;
  549. struct    GDRstruct GDR;
  550.  
  551. struct    attrSTRUCT *CURattr;    /* current attribute */
  552. struct    entrySTRUCT *CURentry;    /* current entry (of the current attribute) */
  553. struct    varSTRUCT *CURvar;    /* current variable */
  554. long    CURentryNum;        /* currently selected entry number (a
  555.                    corresponding entry in the current
  556.                    attribute does not have to exist yet */
  557. struct    varSTRUCT *varHead;
  558. struct    varSTRUCT *varTail;
  559. struct    varSTRUCT *var[CDF_MAX_VARS];    /* These are short cuts to the
  560.                        variable structures */
  561. struct    attrSTRUCT *attrHead;
  562. struct    attrSTRUCT *attrTail;
  563. };
  564.  
  565. /******************************************************************************
  566. * Determine disposition of status.  Note the 'return' statement if the status
  567. * is an error.
  568. *
  569. * For each call to the CDF library, status is returned as follows.
  570. *
  571. *  1. The first ERROR encountered terminates the call and is returned.
  572. *  2. The last WARNING encountered is returned.  INFOs encountered after a
  573. *     WARNING are ignored.
  574. *  3. In the absence of any WARNINGs, the last INFO is returned.
  575. *  4. In the absence of any WARNINGs or INFOs, CDF_OK is returned.
  576. *
  577. ******************************************************************************/
  578.  
  579. #define STATUSdisp(Tstatus,Pstatus) { \
  580. STATUSdispX (Tstatus, &Pstatus); \
  581. if (Pstatus < CDF_WARN) return Pstatus; \
  582. }
  583.  
  584. /******************************************************************************
  585. * Calculate byte offset to variable record if SINGLE file format.
  586. ******************************************************************************/
  587.  
  588. #define SINGLErecOffsetB(Var,recNum,recOffset) { \
  589. struct vixSTRUCT *Vix = Var->vixHead; \
  590. long _i; \
  591. recOffset = -1; \
  592. for (;;) { \
  593.    for (_i = 0; _i < Vix->VXR.NusedEntries; _i++) \
  594.       if (Vix->VXR.FirstRec[_i] <= recNum && \
  595.       recNum <= Vix->VXR.LastRec[_i]) { \
  596.     recOffset = Vix->VXR.VVRoffset[_i] + VVR_BASE_SIZE + \
  597.             Var->NphyRecBytes * (recNum - Vix->VXR.FirstRec[_i]); \
  598.     break; \
  599.       }    \
  600.    if (recOffset != -1) break; \
  601.    Vix = Vix->vixNext; \
  602.    if (Vix == NULL) break; \
  603. } \
  604. }
  605.  
  606. /******************************************************************************
  607. * Calculate byte offset within variable record for given set of indices.
  608. ******************************************************************************/
  609.  
  610. #define INDICESoffsetB(numDims,Var,indices,Boffset) { \
  611. long _dimN; \
  612. Boffset = 0; \
  613. for (_dimN = 0; _dimN < numDims; _dimN++) \
  614.    if (Var->VDR.DimVarys[_dimN]) \
  615.      Boffset += Var->products[_dimN] * indices[_dimN]; \
  616. Boffset *= Var->NvalueBytes; \
  617. }
  618.  
  619. /******************************************************************************
  620. * Calculate value offset within variable record for given set of indices.
  621. ******************************************************************************/
  622.  
  623. #define INDICESoffsetV(numDims,Var,indices,Voffset) { \
  624. long _dimN; \
  625. Voffset = 0; \
  626. for (_dimN = 0; _dimN < numDims; _dimN++) \
  627.    if (Var->VDR.DimVarys[_dimN]) \
  628.      Voffset += Var->products[_dimN] * indices[_dimN]; \
  629. }
  630.  
  631. /******************************************************************************
  632. * Calculate indices for a value offset within variable record (Row major).
  633. ******************************************************************************/
  634.  
  635. #define RowVoffsetINDICES(numDims,Var,Voffset,indices) { \
  636. long _VoffsetT = Voffset; \
  637. long _dimN; \
  638. for (_dimN = 0; _dimN < numDims; _dimN++) { \
  639.    if (Var->VDR.DimVarys[_dimN]) { \
  640.      indices[_dimN] = _VoffsetT / Var->products[_dimN]; \
  641.      _VoffsetT = _VoffsetT % Var->products[_dimN]; \
  642.    } \
  643.    else \
  644.      indices[_dimN] = 0; \
  645. } \
  646. }
  647.  
  648. /******************************************************************************
  649. * Calculate indices for a value offset within variable record (Column major).
  650. ******************************************************************************/
  651.  
  652. #define ColVoffsetINDICES(numDims,Var,Voffset,indices) { \
  653. long _VoffsetT = Voffset; \
  654. long _dimN; \
  655. for (_dimN = numDims - 1; _dimN >= 0; _dimN--) { \
  656.    if (Var->VDR.DimVarys[_dimN]) { \
  657.      indices[_dimN] = _VoffsetT / Var->products[_dimN]; \
  658.      _VoffsetT = _VoffsetT % Var->products[_dimN]; \
  659.    } \
  660.    else \
  661.      indices[_dimN] = 0; \
  662. } \
  663. }
  664.  
  665. /******************************************************************************
  666. * Mark a record as unused.
  667. ******************************************************************************/
  668.  
  669. #define WASTErecord(fp,offset,recordsize) { \
  670. long _RecordSize; \
  671. long _RecordType; \
  672. _RecordSize = recordsize; \
  673. _RecordType = UNUSED_; \
  674. Seek (fp, offset, SEEK_SET); \
  675. putint32 (fp, _RecordSize); \
  676. putint32 (fp, _RecordType); \
  677. }
  678.  
  679. /******************************************************************************
  680. * Locate the previous variable on the linked list.  Note that if the linked
  681. * list has been corrupted, the 'for (;;)' loop will continue until a NULL
  682. * pointer is used (not a good thing).
  683. ******************************************************************************/
  684.  
  685. #define FINDprevVar(CDF,Var,prevVar) { \
  686. if (CDF->varHead == Var) \
  687.   prevVar = NULL; \
  688. else { \
  689.   prevVar = CDF->varHead; \
  690.   for (;;) { \
  691.      if (prevVar->varNext == Var) break; \
  692.      prevVar = prevVar->varNext; \
  693.   } \
  694. } \
  695. }
  696.  
  697. /******************************************************************************
  698. * Locate the previous entry on the linked list.  Note that if the linked
  699. * list has been corrupted, the 'for (;;)' loop will continue until a NULL
  700. * pointer is used (not a good thing).
  701. ******************************************************************************/
  702.  
  703. #define FINDprevEntry(Attr,Entry,prevEntry) { \
  704. if (Attr->entryHead == Entry) \
  705.   prevEntry = NULL; \
  706. else { \
  707.   prevEntry = Attr->entryHead; \
  708.   for (;;) { \
  709.      if (prevEntry->entryNext == Entry) break; \
  710.      prevEntry = prevEntry->entryNext; \
  711.   } \
  712. } \
  713. }
  714.  
  715. /******************************************************************************
  716. * MACRO to move C-style string to FORTRAN-style string.
  717. ******************************************************************************/
  718.  
  719. #if defined(vms)
  720. #define CtoFORTstring(Cstring,FORTstring,defaultLen) { \
  721. char *_ptr; \
  722. size_t _len; \
  723. long _i; \
  724. if (! isDESCR(FORTstring,&_ptr,&_len)) { \
  725.   _ptr = FORTstring; \
  726.   _len = defaultLen; \
  727. } \
  728. strncpy (_ptr, Cstring, _len); \
  729. for (_i = strlen(Cstring); _i < _len; _i++) *(_ptr + _i) = ' '; \
  730. }
  731. #endif
  732.  
  733. #if defined(unix)
  734. #define CtoFORTstring(Cstring,FORTstring,length) { \
  735. long _i; \
  736. strncpy (FORTstring, Cstring, length); \
  737. for (_i = strlen(Cstring); _i < length; _i++) FORTstring[_i] = ' '; \
  738. }
  739. #endif
  740.  
  741. /******************************************************************************
  742. * Default fill values.
  743. ******************************************************************************/
  744.  
  745. #if defined(CDFLIB)
  746. char _CDF_BYTEfv = { 0 };
  747. char _CDF_INT1fv = { 0 };
  748. short _CDF_INT2fv = { 0 };
  749. long _CDF_INT4fv = { 0 };
  750. unsigned char _CDF_UINT1fv = { 0 };
  751. unsigned short _CDF_UINT2fv = { 0 };
  752. unsigned long _CDF_UINT4fv = { 0 };
  753. float _CDF_REAL4fv = { 0.0 };
  754. double _CDF_REAL8fv = { 0.0 };
  755. float _CDF_FLOATfv = { 0.0 };
  756. double _CDF_DOUBLEfv = { 0.0 };
  757. double _CDF_EPOCHfv = { 0.0 };
  758. char _CDF_CHARfv = { ' ' };
  759. unsigned char _CDF_UCHARfv = { ' ' };
  760. #else
  761. extern char _CDF_BYTEfv;
  762. extern char _CDF_INT1fv;
  763. extern short _CDF_INT2fv;
  764. extern long _CDF_INT4fv;
  765. extern unsigned char _CDF_UINT1fv;
  766. extern unsigned short _CDF_UINT2fv;
  767. extern unsigned long _CDF_UINT4fv;
  768. extern float _CDF_REAL4fv;
  769. extern double _CDF_REAL8fv;
  770. extern float _CDF_FLOATfv;
  771. extern double _CDF_DOUBLEfv;
  772. extern double _CDF_EPOCHfv;
  773. extern char _CDF_CHARfv;
  774. extern unsigned char _CDF_UCHARfv;
  775. #endif
  776.  
  777. #if defined(CDFLIB)
  778. void *_CDFdefaultFillValues[] =
  779.       { NULL, (void *) &_CDF_INT1fv, (void *) &_CDF_INT2fv, NULL,
  780.                             (void *) &_CDF_INT4fv,
  781.     NULL, NULL, NULL, NULL, NULL,
  782.     NULL, (void *) &_CDF_UINT1fv, (void *) &_CDF_UINT2fv, NULL,
  783.                             (void *) &_CDF_UINT4fv,
  784.     NULL, NULL, NULL, NULL, NULL,
  785.     NULL, (void *) &_CDF_REAL4fv, (void *) &_CDF_REAL8fv, NULL, NULL,
  786.     NULL, NULL, NULL, NULL, NULL,
  787.     NULL, (void *) &_CDF_EPOCHfv, NULL, NULL, NULL,
  788.     NULL, NULL, NULL, NULL, NULL,
  789.     NULL, (void *) &_CDF_BYTEfv, NULL, NULL, (void *) &_CDF_FLOATfv,
  790.     (void *) &_CDF_DOUBLEfv, NULL, NULL, NULL, NULL,
  791.     NULL, (void *) &_CDF_CHARfv, (void *) &_CDF_UCHARfv, NULL, NULL,
  792.     NULL, NULL, NULL, NULL, NULL };
  793. #else
  794. extern void *_CDFdefaultFillValues[];
  795. #endif
  796.  
  797. /******************************************************************************
  798. * Single element sizes (bytes) for each data type.
  799. ******************************************************************************/
  800.  
  801. #if defined(CDFLIB)
  802. long _CDFelemSizes[] = {0,1,2,0,4,0,0,0,0,0,
  803.                 0,1,2,0,4,0,0,0,0,0,
  804.                 0,4,8,0,0,0,0,0,0,0,
  805.                 0,8,0,0,0,0,0,0,0,0,
  806.                 0,1,0,0,4,8,0,0,0,0,
  807.                 0,1,1,0,0,0,0,0,0,0};
  808. #else
  809. extern long _CDFelemSizes[];
  810. #endif
  811.  
  812. /******************************************************************************
  813. * "Equivalent" data types (if values are the same in this array).
  814. ******************************************************************************/
  815.  
  816. #if defined(CDFLIB)
  817. long _CDFequivTypes[] = {0,1,2,0,3,0,0,0,0,0,
  818.                  0,1,2,0,3,0,0,0,0,0,
  819.                  0,4,5,0,0,0,0,0,0,0,
  820.                  0,5,0,0,0,0,0,0,0,0,
  821.                  0,1,0,0,4,5,0,0,0,0,
  822.                  0,1,1,0,0,0,0,0,0,0};
  823. #else
  824. extern long _CDFequivTypes[];
  825. #endif
  826.  
  827. /******************************************************************************
  828. * CDF copyright.
  829. ******************************************************************************/
  830.  
  831. #if defined(CDFLIB)
  832. char _CDF_CopyRight[] =
  833. "\nNSSDC Common Data Format\n\
  834. (C) Copyright 1990,1991,1992 NASA/GSFC\n\
  835. National Space Science Data Center\n\
  836. NASA/Goddard Space Flight Center\n\
  837. Greenbelt, Maryland 20771 USA\n\
  838. (SPAN -- NSSDCA::CDFSUPPORT)\n\
  839. (Internet -- CDFSUPPORT@NSSDCA.GSFC.NASA.GOV)\n";
  840. #else
  841. extern char _CDF_CopyRight[];
  842. #endif
  843.  
  844. /*****************************************************************************
  845. * CDF data.  This array is indexed by CDFid.  A value of NULL indicates that
  846. * the corresponding CDFid is available for use.  Needless to say the number
  847. * of NULLs must agree with the value of CDF_MAX_CDFS.
  848. *****************************************************************************/
  849.  
  850. #if defined(CDFLIB)
  851. struct cdfSTRUCT *_CDFs[CDF_MAX_CDFS] =
  852. { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  853.   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  854.   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  855.   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  856.   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  857.   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  858.   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  859.   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  860.   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  861.   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  862.   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  863.   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  864.   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
  865. #else
  866. extern struct cdfSTRUCT *_CDFs[];
  867. #endif
  868.  
  869. /******************************************************************************
  870. * Encoding of host machine.
  871. ******************************************************************************/
  872.  
  873. #if defined(CDFLIB)
  874. #if defined(sun)
  875. long _CDFhostEncoding = SUN_ENCODING;
  876. #endif
  877. #if defined(vax)
  878. long _CDFhostEncoding = VAX_ENCODING;
  879. #endif
  880. #if defined(MIPSEL)
  881. long _CDFhostEncoding = MIPSEL_ENCODING;
  882. #endif
  883. #if defined(MIPSEB)
  884. long _CDFhostEncoding = MIPSEB_ENCODING;
  885. #endif
  886. #if defined(__IBMPC__)
  887. long _CDFhostEncoding = IBMPC_ENCODING;
  888. #endif
  889. #if defined(IBMRS)
  890. long _CDFhostEncoding = IBMRS_ENCODING;
  891. #endif
  892. #if defined(HP)
  893. long _CDFhostEncoding = HP_ENCODING;
  894. #endif
  895. #else
  896. extern long _CDFhostEncoding;
  897. #endif
  898.  
  899. /******************************************************************************
  900. * Miscellaneous variables.
  901. ******************************************************************************/
  902.  
  903. #if defined(CDFLIB)
  904. struct cdfSTRUCT *_CURcdf = NULL;
  905. CDFstatus _CURstatus = RESERVED_CDFSTATUS;
  906. long _CDFpseudo_clock = 0;
  907. #else
  908. extern struct cdfSTRUCT *_CURcdf;
  909. extern CDFstatus _CURstatus;
  910. extern long _CDFpseudo_clock;
  911. #endif
  912.  
  913. /******************************************************************************
  914. * Function prototypes.
  915. ******************************************************************************/
  916.  
  917. #if defined(vms) | defined(__MSDOS__)
  918. void STATUSdispX (CDFstatus, CDFstatus *);
  919. int strcmpITB (char *, char *);
  920. void Free_CDFid (struct cdfSTRUCT *);
  921. CDFstatus CloseLRUvar (void);
  922. File *OpenFile (char *, char *);
  923. void calcVarParms (struct cdfSTRUCT *, struct varSTRUCT *);
  924. CDFstatus OpenVar (struct cdfSTRUCT *, struct varSTRUCT *);
  925. CDFstatus FillRecords (struct cdfSTRUCT *, struct varSTRUCT *, long, long);
  926. CDFstatus AllocateRecords (struct cdfSTRUCT *, struct varSTRUCT *, long,
  927.                Boolean);
  928. void calc_V20_eof (struct cdfSTRUCT *);
  929. CDFstatus CloseCDFfiles (struct cdfSTRUCT *);
  930. CDFstatus ReopenCDFforWrite (struct cdfSTRUCT *);
  931.  
  932. void incr_hypIndices_ROW (long *, long, long *, long *, long *, long *,
  933.               Boolean *, Boolean *, long *);
  934. void incr_hypIndices_COL (long, long *, long, long *, long *, long *, long *,
  935.               Boolean *, Boolean *, long *);
  936. CDFstatus HyperGetBytes (struct varSTRUCT *, long, long, void *);
  937. CDFstatus HyperPutBytes (struct varSTRUCT *, long, long, void *);
  938. CDFstatus HyperAccess (struct varSTRUCT *, void *, long, long);
  939.  
  940. CDFstatus CDFcre (va_list *, long, long *);
  941. CDFstatus CDFope (va_list *, long, long *);
  942. CDFstatus CDFdel (long, long *);
  943. CDFstatus CDFclo (long, long *);
  944. CDFstatus CDFget (va_list *, long, long *);
  945. CDFstatus CDFput (va_list *, long, long *);
  946. CDFstatus CDFsel (va_list *, long, long *);
  947. CDFstatus CDFcon (va_list *, long, long *);
  948.  
  949. #if defined(vms)
  950. CDFstatus read_V1_header (struct cdfSTRUCT *);
  951. #endif
  952.  
  953. CDFstatus read_V2_header (struct cdfSTRUCT *);
  954. CDFstatus write_V2_header (struct cdfSTRUCT *);
  955.  
  956. #if defined(vms)
  957. CDFstatus initializeCDFinfo (CDFid);
  958. CDFstatus inquireCDFinfo (CDFid, struct CDFinfoStruct *);
  959. void freeAttrInfo (struct attrInfoStruct *);
  960. CDFstatus putAttrInfo (CDFid, long, long, long);
  961. CDFstatus getAttrInfo (CDFid, long, long *, long *);
  962. #endif
  963.  
  964. #if defined(vms)
  965. long CDFV2dataType (char *);
  966. CDFstatus CDFV1varNum (CDFid, void *, long *);
  967. CDFstatus CDFV1attrNum (CDFid, void *, long *);
  968. CDFstatus CDFV1attrEntryNum (CDFid, void *, long *);
  969. long CDFrcode (CDFstatus);
  970. void CDFV1_data_type (long, long, char *, long *);
  971. #endif
  972.  
  973. char *NULterminate (char *, size_t);
  974.  
  975. #if defined(vms)
  976. Boolean isDESCR (void *, char **, size_t *);
  977. char *DESCRtoREF (void *);
  978. char *DESCRtoREFnul (void *, size_t);
  979. #endif
  980.  
  981. Boolean validCDFname (char *);
  982. Boolean validVarName (char *);
  983. Boolean validAttrName (char *);
  984. Boolean validDataType (long);
  985. Boolean validAttrScope (long);
  986. Boolean validEncoding (long, long *);
  987.  
  988. void xdr_decode (long, long, void *);
  989. void xdr_encode (long, long, void *, void *);
  990.  
  991. #if defined(__MSDOS__)
  992. long htonl (long);
  993. short htons (short);
  994. long ntohl (long);
  995. short ntohs (short);
  996. #endif
  997.  
  998. #if defined(vms)
  999. int fix512 (char *);
  1000. #endif
  1001. #endif
  1002.  
  1003.  
  1004. #if defined(unix)
  1005. void STATUSdispX ();
  1006. int strcmpITB ();
  1007. void Free_CDFid ();
  1008. CDFstatus CloseLRUvar ();
  1009. File *OpenFile ();
  1010. void calcVarParms ();
  1011. CDFstatus OpenVar ();
  1012. CDFstatus FillRecords ();
  1013. CDFstatus AllocateRecords ();
  1014. void calc_V20_eof ();
  1015. CDFstatus CloseCDFfiles ();
  1016. CDFstatus ReopenCDFforWrite ();
  1017.  
  1018. void incr_hypIndices_ROW ();
  1019. void incr_hypIndices_COL ();
  1020. CDFstatus HyperGetBytes ();
  1021. CDFstatus HyperPutBytes ();
  1022. CDFstatus HyperAccess ();
  1023.  
  1024. CDFstatus CDFcre ();
  1025. CDFstatus CDFope ();
  1026. CDFstatus CDFdel ();
  1027. CDFstatus CDFclo ();
  1028. CDFstatus CDFget ();
  1029. CDFstatus CDFput ();
  1030. CDFstatus CDFsel ();
  1031. CDFstatus CDFcon ();
  1032.  
  1033. #if 0
  1034. CDFstatus read_V1_header ();
  1035. #endif
  1036.  
  1037. CDFstatus read_V2_header ();
  1038. CDFstatus write_V2_header ();
  1039.  
  1040. #if 0
  1041. CDFstatus initializeCDFinfo ();
  1042. CDFstatus inquireCDFinfo ();
  1043. void freeAttrInfo ();
  1044. CDFstatus putAttrInfo ();
  1045. CDFstatus getAttrInfo ();
  1046. #endif
  1047.  
  1048. char *NULterminate ();
  1049.  
  1050. #if 0
  1051. Boolean isDESCR ();
  1052. char *DESCRtoREF ();
  1053. char *DESCRtoREFnul ();
  1054. #endif
  1055.  
  1056. Boolean validCDFname ();
  1057. Boolean validVarName ();
  1058. Boolean validAttrName ();
  1059. Boolean validDataType ();
  1060. Boolean validAttrScope ();
  1061. Boolean validEncoding ();
  1062.  
  1063. void xdr_decode ();
  1064. void xdr_encode ();
  1065.  
  1066. long htonl ();
  1067. short htons ();
  1068. long ntohl ();
  1069. short ntohs ();
  1070.  
  1071. #if 0
  1072. int fix512 ();
  1073. #endif
  1074. #endif
  1075.  
  1076. /*****************************************************************************/
  1077.  
  1078. #endif    /*___cdflib_h___*/
  1079.